package com.riteny.util.exception.entity;


import java.io.Serializable;

public class RestResponseTemplate<T> implements Serializable {

    private String resultCode;
    private String resultMsg;
    private String requestId;
    private T data;


    public RestResponseTemplate() {
    }

    public RestResponseTemplate(String resultCode, String resultMsg, T data) {
        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
        this.data = data;
    }

    public RestResponseTemplate<T> normalRestResponseTemplate(T data) {

        this.setResultCode(CommonHttpClientException.STATUS_SUCCESS);
        this.setResultMsg("");
        this.setData(data);

        return this;
    }

    public RestResponseTemplate<T> normalRestResponseTemplate(String requestId, T data) {

        this.setResultCode(CommonHttpClientException.STATUS_SUCCESS);
        this.setResultMsg("");
        this.setData(data);
        this.setRequestId(requestId);

        return this;
    }

    public RestResponseTemplate<T> normalRestResponseTemplate() {

        this.setResultCode(CommonHttpClientException.STATUS_SUCCESS);
        this.setResultMsg("");

        return this;
    }

    public RestResponseTemplate<T> exceptionRestResponseTemplate(String resultMsg) {

        this.setResultCode(CommonHttpClientException.STATUS_ERROR);
        this.setResultMsg(resultMsg);

        return this;
    }

    public RestResponseTemplate<T> exceptionRestResponseTemplate() {

        this.setResultCode(CommonHttpClientException.STATUS_ERROR);
        this.setResultMsg("");

        return this;
    }

    public String getResultCode() {
        return resultCode;
    }

    public void setResultCode(String resultCode) {
        this.resultCode = resultCode;
    }

    public String getResultMsg() {
        return resultMsg;
    }

    public void setResultMsg(String resultMsg) {
        this.resultMsg = resultMsg;
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "RestResponseTemplate{" +
                "resultCode='" + resultCode + '\'' +
                ", resultMsg='" + resultMsg + '\'' +
                ", requestId='" + requestId + '\'' +
                ", datasource=" + data +
                '}';
    }
}
